{template 'common/header'}
<style>
	*{box-sizing: content-box!important;}
</style>
<div class="page-group">
    <div class="page page-current" id="page-goods-list">
		{template 'followed'}
		{template 'common/footbar'}
		<div class="content infinite-scroll native-scroll" data-distance="10">
		<form id="form1" action="{php echo $this->createMobileUrl('cart',array('op'=>'totalcart'))}" method="post">
		<div class="m-simpleFooter" id="pro-view-3" style="bottom: 2.5rem;">
			{if m('user')->followed() != 1 && $this->module['config']['followed_isbuy'] == 2}
			<div data-pro="text" class="m-simpleFooter-text">
				<div id="pro-view-4">
					{php echo $this->module['config']['followed_message']}
				</div>
			</div>
			<div data-pro="ext" class="m-simpleFooter-ext" >
				<a class="w-button w-button-main" href="javascript:$('#m_popUp').show()">
					立即关注
				</a>
			</div>
			{else}
			<div data-pro="text" class="m-simpleFooter-text">
				<div id="pro-view-4">
					共<span id="goodsnum">{$myCart_num}</span>件商品，总计：<em class="txt-red" id="total">{$money}</em>&nbsp;夺宝币(<span id="re">点击刷新</span>)
				</div>
			</div>
			<div data-pro="ext" class="m-simpleFooter-ext" >
				<a class="w-button w-button-main {if empty($myCart)} w-button-disabled{/if}" id="submit">
					提交
				</a>
			</div>
			{/if}
		</div>
		<div class="m-cart" id="pro-view-5">
			{loop $myCart $goods}
			<input type="hidden" id="addnum{$goods['id']}"  value="{$goods['init_money']}">
			<div class="item"  id="div{$goods['id']}">
				<div class="pic">
					<a href="{php echo $this->createMobileUrl('detail', array('id' => $goods['goodsid']))}">
						<img src="{php echo tomedia($goods['picarr']);}" alt="">
					</a>
				</div>
				<div class="text">
					<h1 class="titlee">
						<a href="{php echo $this->createMobileUrl('detail', array('id' => $goods['goodsid']))}">
							{$goods['title']}
						</a>
					</h1>
					<div>
						总需 {$goods['zong_codes']} 人次，剩余最大购买次数 <em class="remain" id="shengyu{$goods['id']}">{if $goods['shengyu_codes'] >= $goods['left'] && $goods['left']!= -1} {$goods['left']} {else}{$goods['shengyu_codes']}{/if}</em> 人次
					</div>
					<input type="hidden" id="period_number{$goods['id']}" name="goods[]" value="{$goods['period_number']}">
					<input type="hidden" id="title{$goods['id']}"  value="{$goods['title']}">
					{if $goods['shengyu_codes'] == 0 || $goods['left'] == 0}
					购买次数达到上限，请删除该商品
					{else}
					<div>
						参与人次
						<div class="w-number" id="pro-view-7">
							<input class="w-number-input" type="tel" id="num{$goods['id']}" name="num[]" value="{if $goods['left']==0}0{else}{$goods['num']}{/if}">
							<a class="w-number-btn w-number-btn-plus" id="up{$goods['id']}">
								+
							</a>
							<a class="w-number-btn w-number-btn-minus" id="down{$goods['id']}">
								-
							</a>
						</div>
						<p style="color: #FF0618;" id="init_money{$goods['id']}">￥{if $goods['left']==0}0{else}{php echo $goods['num']*$goods['init_money']}{/if}</p>
					</div>
					{/if}
					<a href="javascript:void(0);" data-pro="del" class="del" id="remove{$goods['id']}">
						<i class="ico ico-del" >
						</i>
					</a>
				</div>
			</div>
			<script>
			/******************刷新购物车js开始***********************/
				$('#re').bind('click',function(){
					location.reload();
				});
			/******************刷新购物车js开始***********************/
			/******************提交支付js开始***********************/
				$('#submit').bind('click',function(){
					var total = $('#total').html();
						total = parseInt(total);
					if(!isNaN(total)){
						if(total<=0){
							tip("并没有填写购买量！",true);
							return false;
						}
					}else{
						tip("错误！",true);return false;
					}
					setTimeout(function(){$('#form1').submit();}, 300);
					
				});
			/******************提交支付js结束***********************/
			/******************填写修改数量js开始***********************/
				$("#num{$goods['id']}").change(function(){
					var num = document.getElementById("num{$goods['id']}").value;
					var shengyu = $('#shengyu{$goods['id']}').html();
						shengyu = parseInt(shengyu);
					var init_money = $('#addnum{$goods['id']}').val(); 
						if(isNaN(num) || num<=0){
							//判定输入是否是整数
							num = 1;
							$('#num{$goods['id']}').val(num);
						}else{							
							if(shengyu<num){
								//判定剩余数量和输入数量大小
								num = shengyu;
								tip("兄弟,剩的不多啦!",true);			
							}
							$('#num{$goods['id']}').val(num);
						}						
					var periodnumber = $('#period_number{$goods['id']}').val();
					var title = $('#title{$goods['id']}').val();
					$.post("{php echo $this->createMobileUrl('cart',array('op'=>'tocart','type'=>'input'))}",{num:num,periodnumber:periodnumber,title:title},function(d){
							var goodsnum = d.num;
							var allmoney = d.money;
							document.getElementById('init_money{$goods['id']}').innerHTML = "￥"+num*init_money;
							$('#total').html(allmoney);
							$('#goodsnum').html(goodsnum);	
					},"json");
				
				});
			/******************填写修改数量js结束***********************/
			/******************增加数量js开始***********************/
				$("#up{$goods['id']}").bind('click',function(){
					var num = $('#num{$goods['id']}').val();
					var shengyu = $('#shengyu{$goods['id']}').html();
					var init_money = $('#addnum{$goods['id']}').val(); 
						addnum = 1;
						num = parseInt(num);
						shengyu = parseInt(shengyu);
					if(shengyu<=num){
						tip("兄弟,剩的不多啦!",true);
						return false;
					}
					num =  parseInt(num) + addnum; 
					$('#num{$goods['id']}').val(num);
					document.getElementById('init_money{$goods['id']}').innerHTML = "￥"+num*init_money;
					var periodnumber = $('#period_number{$goods['id']}').val();
					var title = $('#title{$goods['id']}').val();
					$.post("{php echo $this->createMobileUrl('cart',array('op'=>'tocart','type'=>'up'))}",{periodnumber:periodnumber,title:title},function(d){
							var goodsnum = d.num;
							var allmoney = d.money;
							$('#total').html(allmoney);
							$('#goodsnum').html(goodsnum);	
					},"json");
					
				});
			/******************增加数量js结束***********************/
			/******************减少数量js开始***********************/
				$("#down{$goods['id']}").bind('click',function(){
					var num = $('#num{$goods['id']}').val();
					var init_money = $('#addnum{$goods['id']}').val(); 
						addnum = 1;
					num =  parseInt(num) - addnum; 
					if(num<=0){
						num=1;
						tip("购买0个有意思吗？",true);
						return false;
					}
					$('#num{$goods['id']}').val(num);
					document.getElementById('init_money{$goods['id']}').innerHTML = "￥"+num*init_money;
					var money = $('#total').html();
					if(num>0){
						var periodnumber = $('#period_number{$goods['id']}').val();
						var title = $('#title{$goods['id']}').val();
						$.post("{php echo $this->createMobileUrl('cart',array('op'=>'tocart','type'=>'down'))}",{periodnumber:periodnumber,title:title},function(d){
							var goodsnum = d.num;
							var allmoney = d.money;
							$('#total').html(allmoney);
							$('#goodsnum').html(goodsnum);
						},"json");
						}
					});
				/******************减少数量js结束***********************/
				/******************移除商品js开始***********************/
					//remove
					$("#remove{$goods['id']}").bind('click',function(){
					var periodnumber = $('#period_number{$goods['id']}').val();
					var title = $('#title{$goods['id']}').val();
					$.post("{php echo $this->createMobileUrl('cart',array('op'=>'tocart','type'=>'remove'))}",{periodnumber:periodnumber,title:title},function(d){
						if(d.result==1){
							var goodsnum = d.num;
							var allmoney = d.money;
							$('#total').html(allmoney);
							$('#goodsnum').html(goodsnum);
							$('#div{$goods['id']}').hide();
							$('#div{$goods['id']}').remove();
							if(allmoney==0){
								$('#submit').addClass('w-button-disabled');
								$('#s').css('display','block');
							}
						}
					},"json");
				});
			/******************移除商品js结束***********************/	
			</script>
			{/loop}
		</div>
		</form>
		<div class="m-cart" id="s" {if empty($myCart)}style="display:block";{else}style="display:none";{/if}><div class="empty" id="pro-view-6">您的清单里还没有任何商品，<a href="{php echo $this->createMobileUrl('index')}">马上去逛逛~</a></div></div>
		</div>
	</div>
</div>
</body>
{template 'common_message'}
</html>